package com.zmx.user.repository;

import com.zmx.common.common.repository.BaseRepository;
import com.zmx.user.entity.MemberBlacklist;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author zhaomxr
 */
public interface MemberBlacklistRepository extends BaseRepository<MemberBlacklist> {

    @Query(value = "select * from member_blacklist where (member_id = ?1 or ip = ?2) and begin_time <= now() and end_time >= now() and dr = 0 and is_relieve = 0 order by create_time desc", nativeQuery = true)
    List<MemberBlacklist> findByMemberIdOrIp(Long memberId, String ip);

    @Query(value = "select * from member_blacklist where member_id = ?1 and begin_time <= now() and end_time >= now() and dr = 0 and is_relieve = 0 order by create_time desc", nativeQuery = true)
    List<MemberBlacklist> findByMemberId(Long memberId);

    @Query(value = "select * from member_blacklist where ip = ?1 and begin_time <= now() and end_time >= now() and dr = 0 and is_relieve = 0 order by create_time desc", nativeQuery = true)
    List<MemberBlacklist> findByIp(String ip);
}
